package com.bondar.task3;

public class Producer<T> implements Runnable {

	private Buffer<T> buffer;
	private T[] arr;

	public Producer(Buffer<T> buffer, T[] arr) {
		this.buffer = buffer;
		this.arr = arr;
	}

	@Override
	public void run() {
		int i=0;
		String threadName = Thread.currentThread().getName();

		while(i < arr.length){
			try {
				System.out.println(String.format("%s: try to put %s", threadName, arr[i]));
				buffer.put(arr[i]);
				System.out.println(String.format("%s: putted %s", threadName, arr[i]));
				System.out.println(String.format("#####%s end operation#####", threadName));
//				i = i+1 >= arr.length ? 0 : i+1;
				++i;
			} catch (InterruptedException e) {
				e.printStackTrace();
			}
		}
	}

}
